/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import hibernate.impl.GroupDAOImpl;
import hibernate.impl.RoleDAOImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import modelmapping.Group;
import modelmapping.Role;

/**
 *
 * @author Valentina
 */
public class PentaUtil {

    public PentaUtil() {
    }

    public static void RequestUtil(HttpServletRequest request, HttpServletResponse response, String path)
            throws ServletException, IOException {

        RequestDispatcher rd = null;

        rd = request.getRequestDispatcher(path);
        rd.forward(request, response);
    }

    public static void getGroupLits(HttpServletRequest request) {
        GroupDAOImpl groupDAOImpl = new GroupDAOImpl();
        List<Group> groups = (List<Group>) groupDAOImpl.retrieve();
        request.setAttribute("groups", groups);
    }

    public static void getRoleLits(HttpServletRequest request) {
        RoleDAOImpl roleDAOImpl = new RoleDAOImpl();
        List<Role> roles = (List<Role>) roleDAOImpl.retrieve();
        request.setAttribute("roles", roles);
    }

    public static void setError(HttpServletRequest request, HttpServletResponse response, List myErrors)
            throws ServletException, IOException {
        request.setAttribute("myErrors", myErrors);
        PentaUtil.RequestUtil(request, response, "WEB-INF/frontend/PageError.jsp");
    }   
}